const fs = require('fs');
const shell =require("shelljs");
// let intype = process.argv[2]||'vue' //入口文件类型
  // 获取需要更新的组件目录
let libarr = fs.readFileSync('./needUpdateLibs.txt','utf-8')
if(libarr){
  libarr = libarr.split(',')
  for(let item of libarr){
    const fileUrl = item;
    const fileName = item.split('/').pop()
    console.log('*************************',fileUrl,'/n'+'fileName=',fileName,fileUrl.replace('dev','build'))
    // 入口文件夹是否有index.js
    fs.access(fileUrl+'/index.js', (err) => {
        if (err) {
          shell.exec(`node ./node_modules/@vue/cli-service/bin/vue-cli-service.js build --target lib --name ${fileName} --dest ${fileUrl.replace('dev','build/')} ${fileUrl}/index.vue`);
        } else {
          shell.exec(`node ./node_modules/@vue/cli-service/bin/vue-cli-service.js build --target lib --name ${fileName} --dest ${fileUrl.replace('dev','build/')} ${fileUrl}/index.js`);
        }
    })
  }
  // 打包完后清空txt
  fs.writeFile('./needUpdateLibs.txt', '',()=>{
    console.log('清空needUpdateLibs.txt成功')
  })
}else{
  console.log('没有需要更新的组件库')
}
